package com.feiaho.zhou.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Controller
public class TestController {
    @RequestMapping("/test01")
    @ResponseBody
    public void test01(){

        String string= null;
        string.equals("dd");
        System.out.println("Test01  rrrrr");
    }



    @RequestMapping("/upload")
    @ResponseBody
    public String upload(MultipartFile file) throws IOException {
        file.transferTo(new File("qwe.png"));
        return "上传ok";
    }

    @RequestMapping("/upload1")
    @ResponseBody
    public String upload1(MultipartFile[] file1, HttpServletRequest request) throws IOException {
        if (file1!=null){
            for (MultipartFile file : file1) {
                file.transferTo(new File(request.getServletContext().getRealPath("/img") , UUID.randomUUID().toString()+file.getOriginalFilename()));
            }
        }
        return "上传ok";
    }
}
